/**
 *
 */
package de.hsbremen.dirtybox;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;

/**
 * @author andreas.ehlert
 *
 */
public class MainActivity extends TabActivity {

	private static final String ID = "_ID";
	private static final String FOLDER_NAME = "FolderName";
	private static final String PARENT_FOLDER_ID = "ParentFolderID";

	private final DirtySQLiteDatabase database = new DirtySQLiteDatabase(this);
	// private List<ImageView> symbolViews = new ArrayList<ImageView>();
//	private Stack<TableRow> rows;
//	private final List<ImageView> symbolViews = new Vector<ImageView>();

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		initializeTabHost();
	    createSQLPrintButton();
	}

	private void initializeTabHost() {
		final Resources res = getResources(); // Resource object to get Drawables
	    final TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent; // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, ImagesActivity.class);
	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("image").setIndicator("Bilder",
	                      res.getDrawable(R.drawable.gallery))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    intent = new Intent().setClass(this, VideosActivity.class);
	    spec = tabHost.newTabSpec("video").setIndicator("Videos",
	                      res.getDrawable(R.drawable.videos))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, MessagesActivity.class);
	    spec = tabHost.newTabSpec("message").setIndicator("Nachrichten",
	                      res.getDrawable(R.drawable.messages))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, ContactsActivity.class);
	    spec = tabHost.newTabSpec("contact").setIndicator("Kontakte",
	    		res.getDrawable(R.drawable.contacts))
	    		.setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(0);
	}

	private void createSQLPrintButton() {
		//final Button buttonTest = (Button) findViewById(R.id.sqlprint);
		/*buttonTest.setOnClickListener(new OnClickListener() {
			public void onClick(final View arg0) {
				final StringBuffer buffer = new StringBuffer();
				buffer.append("#####  TEST  #####");
				Cursor cursor = database.getReadableDatabase().query(
						"folder", null, null, null, null, null, null);
				if (cursor.moveToFirst()) {
					do {
						buffer.append("\nfolder -> ID: " + cursor.getInt(cursor.getColumnIndex(ID))
								+ " | Name: " + cursor.getString(cursor.getColumnIndex(FOLDER_NAME))
								+ " | PFID: " + cursor.getString(cursor.getColumnIndex(PARENT_FOLDER_ID)));
					} while (cursor.moveToNext());
				}
				else {
					buffer.append("\nfolder -> NO folders found!");
				}

				cursor = database.getReadableDatabase().query("image", null,
						null, null, null, null, null);
				if (cursor.moveToFirst()) {
					do {
						buffer.append("\nimage -> ID: " + cursor.getInt(cursor.getColumnIndex(ID))
								+ " | PFID: " + cursor.getInt(cursor.getColumnIndex(PARENT_FOLDER_ID)));
					} while (cursor.moveToNext());
				}
				else {
					buffer.append("\nimage -> NO images found!");
				}

				buffer.append("\n#####  TEST  #####");

				cursor.close();
				database.close();

				// Bring the result to the display in a dialog
				// as well as show it in the Log.
				Log.d("MobileShoppinglistActivity", buffer.toString());
				new AlertDialog.Builder(MainActivity.this).
				setMessage(buffer.toString()).
				create().
				show();
			}
		});*/
	}
}
